﻿namespace OnHook.Common.Extension
{
    /// <summary>
    /// 数字处理扩展方法
    /// </summary>
    public static class DecimalExtension
    {
        /// <summary>
        /// 精确的小数点后几位
        /// </summary>
        /// <param name="num"></param>
        /// <param name="fix"></param>
        /// <param name="round"></param>
        /// <returns></returns>
        public static decimal ToFixed(this decimal num, int fix = 2, MidpointRounding round = MidpointRounding.AwayFromZero)
        {
            decimal value = Math.Round(num, fix, round);
            return value;
        }

        /// <summary>
        /// 现金精确到小数点后几位（*100，再除以100）；
        /// </summary>
        /// <param name="m"></param>
        /// <param name="fix"></param>
        /// <returns></returns>
        public static decimal MoneyHander(this decimal m, int fix = 2)
        {
            return Math.Round(((Int32)(m * 100)) / 100.0m, fix);
        }

    }
}
